package org.feng.client;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.feng.client.request.ImageClassifyRequest;
import org.feng.client.response.BaiDuResponse;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * TODO
 *
 * @author feng
 */
@Service
@Slf4j
public class BaiduAiImageClassifyClient extends BaiDuAiClient {

    @SneakyThrows
    public <T extends ImageClassifyRequest, R extends BaiDuResponse> R recognizeImage(T request, Class<R> responseClass) {
        Map<String, Object> params = generateParamMapWithToken();
        request.fillParmaMap(params);
        String result = recognizeImage(baiDuAiProperties.getBaseUrl() + request.getPath(), request.getImage(), params);

        log.info("识别结果：{}", result);
        return MAPPER.readValue(result, responseClass);
    }
}
